package sample.factory.simpleFactory;

/**
 * <p>简单工厂试验</p> Gardener：菜园
 *
 * <p>Copyright: 版权所有 (c)<br>
 * Company: 久其</p>
 *
 * @author liyue
 * @version 2013-7-10
 */
public class Main{
	public class Fruit{
		private String name;

		public Fruit(String name){
			this.name = name;
		}

		public String getName(){
			return this.name;
		}

		@Override
		public String toString(){
			return "name is : " + this.name;
		}
	}

	public class Apple extends Fruit{

		public Apple(String name){
			super(name);
		}
	}

	public class Banana extends Fruit{
		public Banana(String name){
			super(name);
		}
	}

	/**
	 * 葡萄
	 */
	public class Grape extends Fruit{

		public Grape(String name){
			super(name);
		}

	}

	public Fruit getFruit(String fruitName){

		if("apple".equalsIgnoreCase(fruitName)){
			return new Apple(fruitName);
		}
		else if("banana".equalsIgnoreCase(fruitName)){
			return new Banana(fruitName);
		}
		else if("grape".equalsIgnoreCase(fruitName)){
			return new Grape(fruitName);
		}
		else{
			return null;
		}
	}

	public static void main(String[] args){
		Main fruitGardener = new Main();
		System.out.println(fruitGardener.getFruit("apple"));
		System.out.println(fruitGardener.getFruit("banana"));
		System.out.println(fruitGardener.getFruit("grape"));
		System.out.println(fruitGardener.getFruit("test"));

	}

}
